package com.isorf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.isorf.mapper.sizemapper;
import com.isorf.mapper.teachermapper;
import com.isorf.pojo.size;
import com.isorf.pojo.type;
import com.isorf.service.sizeservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class sizeserviceimpl implements sizeservice {
    @Autowired
    private sizemapper sizemapper;
    @Override
    public List<size> getallsize() {
        return sizemapper.getallsize();    }

    @Override
    public Boolean deletesize(Integer sizeId) {
        // 先删除关联的库存数据
        sizemapper.deleteInventoryBySizeId(sizeId); // Fixed method name
        // 再删除size记录
        int result = sizemapper.deletesize(sizeId);
        return result > 0;
    }

    @Override
    public Boolean batchDelete(List<Integer> ids) {
        // 先删除 inventorylist 表中关联的记录
        sizemapper.deleteInventoryBySizeIds(ids);
        // 再删除 size 表中的记录
        int result = sizemapper.batchDelete(ids);
        return result > 0;
    }

    @Override
    public PageInfo<size> pageList(int pageNum, int pageSize) {
        // 使用PageHelper.startPage方法设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        // 查询所有用户数据，此时查询会被自动分页
        List<size> userList = (List<size>) sizemapper.pageList();
        // 使用PageInfo包装查询结果，便于页面使用
        return new PageInfo<>(userList);
    }

    @Override
    public Boolean addsize(size size) {
        int result = sizemapper.addsize(size);
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Boolean updatecolor(size size) {
        int result = sizemapper.updatesize(size);
        return result > 0;
    }


}
